<?php

// use Illuminate\Support\Facades\Schema;
use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitExchange extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('exchange_records', function (Blueprint $table) {
            $table->comment = '转换记录表';

            $table->increments('id');
            $table->uuid('uuid')->index() ;

            $table->integer('user_id')->index()->comment('用户id');

            $table->integer('product_id')->index()->comment('置换商城的商品id');
            $table->integer('sku_id')->index()->comment('置换商城的sku id');

            $table->char('order_number', 30)->index()->comment('订单编号');

            // $table->integer('order_id')->index()->commit('置换时支付的订单id');
            // $table->string('title')->nullable()->comment('标题');

            $table->integer('pay_money_price')->default(0)->comment('支付的人民币价格');
            $table->integer('pay_score_price')->default(0)->comment('支付的积分价格');

            $table->integer('source_money_price')->default(0)->comment('置换前的人民币价格');
            $table->integer('source_score_price')->default(0)->comment('置换前的积分价格');

            $table->integer('target_money_price')->default(0)->comment('置换物的人民币价格');
            $table->integer('target_score_price')->default(0)->comment('置换物的积分价格');

            $table->tinyInteger('status')->index()->default(1)->comment('1为待支付 2为已完成兑换 3为已取消');

            $table->softDeletes();
            $table->timestamps();

        });

        Schema::table('package_skus', function (Blueprint $table) {

            $table->tinyInteger('exchange_record_id')->nullable()->index()->comment('兑换记录的id');
            
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::disableForeignKeyConstraints();
        Schema::dropIfExists('exchange_records');
    }
}
